﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Utils
{
    public static class DateTimeHelper
    {
        public static DateTime EndOfMonth(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month + 1, 1).AddDays(-1);
        }

        public static DateTime StartOfMonth(this DateTime dt)
        {
            return new DateTime(dt.Year, dt.Month, 1);
        }

        public static DateTime StartOfWeek(this DateTime dt)
        {
            var week = (int)dt.DayOfWeek;
            week = week == 0 ? 7 : week;
            return dt.Date.AddDays(-week + 1);
        }

        public static DateTime EndOfWeek(this DateTime dt)
        {
            var week = (int)dt.DayOfWeek;
            week = week == 0 ? 7 : week;
            return dt.Date.AddDays(7 - week);
        }
    }
}
